package _220322;

import java.util.Arrays;

/**
 * @author ShadowLim
 * @create 2022-03-22-8:11
 */
public class 算式900 {
    static int INF = 0x7f7f7f7f;
    static int n = 15;
    static int[] a = new int[n];
    static boolean[] vis = new boolean[n];

    public static void main(String[] args) {
        Arrays.fill(a, INF);
        dfs(0);
    }

    private static void dfs(int k) {
        if (k == 10) {
            if ((((a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3]) - (a[4] * 1000 + a[5] * 100 +
                    a[6] * 10 + a[7])) * (a[8] * 10 + a[9]) == 900)) {
                if (a[8] * 10 + a[9] != 36) {
                    System.out.print("(" + a[0] + a[1] + a[2] + a[3] + "-" + a[4] + a[5] + a[6] + a[7]
                            + ")" + "*" + a[8] + a[9] + "=" + 900);
                    System.out.println();
                }
                return;
            }
        } else if (k == 0 || k == 4 || k == 8){  // 第1 5 9位不能为0
            for (int i = 1; i <= 9; i++) {
                if (!vis[i]) {
                    vis[i] = true;
                    a[k] = i;
                    dfs(k + 1);
                    a[k] = INF;
                    vis[i] = false;
                }
            }
        } else {
            for (int i = 0; i <= 9; i++) {
                if (!vis[i]) {
                    vis[i] = true;
                    a[k] = i;
                    dfs(k + 1);
                    a[k] = INF;
                    vis[i] = false;
                }
            }
        }
    }
}
